package com.molichuxing.gateway.utils;

import com.molichuxing.framework.utils.EmailUtil;
import com.molichuxing.gateway.property.EmailTemplateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 用户token工具类
 *
 * @author zoumingyu
 * @date 2019年8月19日
 */
@Component
public class DealerEmailUtil {
    private static final Logger logger = LoggerFactory.getLogger(DealerEmailUtil.class);

    // 开关
    @Value("${email.enable}")
    private String enable;

    @Value("${dealer.system.url}")
    private String dealerSystemUrl;

    @Value("${email_account}")
    private String emailAccount;

    @Value("${email_password}")
    private String emailPassword;

    /**
     * 发送邮件
     *
     * @param subject 标题
     * @param content 内容
     * @param emailTo 收件人
     * @return
     */
    public boolean send(String subject, String content, String emailTo) {
        return EmailUtil.sendMail(emailAccount, emailPassword, subject, content, emailTo);
    }


    /**
     * 创建经销商用户成功
     *
     * @param account
     * @param password
     * @return
     */
    public String editorCreateAccountSuccessContent(String account, String password) {
        String content = EmailTemplateEnum.CREATE_ACCOUNT_SUCCESS.getTemplate();
        content = content.replace("${systemUrl}", dealerSystemUrl);
        content = content.replace("${userName}", account);
        content = content.replace("${password}", password);
        return content;

    }

    /**
     * 创建用户失败
     *
     * @param realName
     * @return
     */
    public String editorCreateAccountErrorContent(String realName) {
        String content = EmailTemplateEnum.CREATE_ACCOUNT_ERROR.getTemplate();
        content = content.replace("${realName}", realName);
        return content;
    }

    public String editorResetPasswordContent(String account, String password) {
        String content = EmailTemplateEnum.RESET_PASSWORD.getTemplate();
        content = content.replace("${userName}", account);
        content = content.replace("${password}", password);
        return content;
    }
}
